﻿using System;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Csla;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;

namespace RMSM
{
    [Serializable()]
    public class KBDienNaoBO : Csla.BusinessBase<KBDienNaoBO>
    {
        #region Business Properties

        private int? _KBDienNaoID = null;
        public int? KBDienNaoID
        {
            get { return this._KBDienNaoID; }
            set { this._KBDienNaoID = value; PropertyHasChanged("KBDienNaoID"); }
        }

        private int? _Status = 0;
        public int? Status
        {
            get { return this._Status; }
            set { this._Status = value; PropertyHasChanged("Status"); }
        }

        private int? _KBDieuTriID = null;
        public int? KBDieuTriID
        {
            get { return this._KBDieuTriID; }
            set { this._KBDieuTriID = value; PropertyHasChanged("KBDieuTriID"); }
        }

        private int? _KBYLenhID = null;
        public int? KBYLenhID
        {
            get { return this._KBYLenhID; }
            set { this._KBYLenhID = value; PropertyHasChanged("KBYLenhID"); }
        }

        private int? _BenhNhanID = null;
        public int? BenhNhanID
        {
            get { return this._BenhNhanID; }
            set { this._BenhNhanID = value; PropertyHasChanged("BenhNhanID"); }
        }

        private int? _NguoiChiDinhID = null;
        public int? NguoiChiDinhID
        {
            get { return this._NguoiChiDinhID; }
            set { this._NguoiChiDinhID = value; PropertyHasChanged("NguoiChiDinhID"); }
        }

        private DateTime? _NgayChiDinh = null;
        public DateTime? NgayChiDinh
        {
            get { return this._NgayChiDinh; }
            set { this._NgayChiDinh = value; PropertyHasChanged("NgayChiDinh"); }
        }

        private int? _NguoiThucHienID = null;
        public int? NguoiThucHienID
        {
            get { return this._NguoiThucHienID; }
            set { this._NguoiThucHienID = value; PropertyHasChanged("NguoiThucHienID"); }
        }

        private DateTime? _NgayThucHien = null;
        public DateTime? NgayThucHien
        {
            get { return this._NgayThucHien; }
            set { this._NgayThucHien = value; PropertyHasChanged("NgayThucHien"); }
        }

        private int? _KhoaThucHienID = null;
        public int? KhoaThucHienID
        {
            get { return this._KhoaThucHienID; }
            set { this._KhoaThucHienID = value; PropertyHasChanged("KhoaThucHienID"); }
        }

        private int? _PhongThucHienID = null;
        public int? PhongThucHienID
        {
            get { return this._PhongThucHienID; }
            set { this._PhongThucHienID = value; PropertyHasChanged("PhongThucHienID"); }
        }

        private int? _DMDienNaoID = null;
        public int? DMDienNaoID
        {
            get { return this._DMDienNaoID; }
            set { this._DMDienNaoID = value; PropertyHasChanged("DMDienNaoID"); }
        }

        private string _KyThuat = null;
        public string KyThuat
        {
            get { return this._KyThuat; }
            set { this._KyThuat = value; PropertyHasChanged("KyThuat"); }
        }

        private string _TinhTrang = null;
        public string TinhTrang
        {
            get { return this._TinhTrang; }
            set { this._TinhTrang = value; PropertyHasChanged("TinhTrang"); }
        }

        private string _SongAlpha = null;
        public string SongAlpha
        {
            get { return this._SongAlpha; }
            set { this._SongAlpha = value; PropertyHasChanged("SongAlpha"); }
        }

        private string _TanSo = null;
        public string TanSo
        {
            get { return this._TanSo; }
            set { this._TanSo = value; PropertyHasChanged("TanSo"); }
        }

        private string _BienDo = null;
        public string BienDo
        {
            get { return this._BienDo; }
            set { this._BienDo = value; PropertyHasChanged("BienDo"); }
        }

        private string _ChiSo = null;
        public string ChiSo
        {
            get { return this._ChiSo; }
            set { this._ChiSo = value; PropertyHasChanged("ChiSo"); }
        }

        private string _PhanUngVoiKichThich = null;
        public string PhanUngVoiKichThich
        {
            get { return this._PhanUngVoiKichThich; }
            set { this._PhanUngVoiKichThich = value; PropertyHasChanged("PhanUngVoiKichThich"); }
        }

        private string _DoiXungHayKhong = null;
        public string DoiXungHayKhong
        {
            get { return this._DoiXungHayKhong; }
            set { this._DoiXungHayKhong = value; PropertyHasChanged("DoiXungHayKhong"); }
        }

        private string _DongHoaNhip = null;
        public string DongHoaNhip
        {
            get { return this._DongHoaNhip; }
            set { this._DongHoaNhip = value; PropertyHasChanged("DongHoaNhip"); }
        }

        private string _SongNhanh = null;
        public string SongNhanh
        {
            get { return this._SongNhanh; }
            set { this._SongNhanh = value; PropertyHasChanged("SongNhanh"); }
        }

        private string _SongCham = null;
        public string SongCham
        {
            get { return this._SongCham; }
            set { this._SongCham = value; PropertyHasChanged("SongCham"); }
        }

        private string _CacPhucBoSong = null;
        public string CacPhucBoSong
        {
            get { return this._CacPhucBoSong; }
            set { this._CacPhucBoSong = value; PropertyHasChanged("CacPhucBoSong"); }
        }

        private byte[] _Anh = null;
        public byte[] Anh
        {
            get { return this._Anh; }
            set { this._Anh = value; PropertyHasChanged("Anh"); }
        }

        private string _KetQua = null;
        public string KetQua
        {
            get { return this._KetQua; }
            set { this._KetQua = value; PropertyHasChanged("KetQua"); }
        }

        private string _KetLuan = null;
        public string KetLuan
        {
            get { return this._KetLuan; }
            set { this._KetLuan = value; PropertyHasChanged("KetLuan"); }
        }

        private string _GhiChu = null;
        public string GhiChu
        {
            get { return this._GhiChu; }
            set { this._GhiChu = value; PropertyHasChanged("GhiChu"); }
        }

        private double? _GiaTien = 0;
        public double? GiaTien
        {
            get { return this._GiaTien; }
            set { this._GiaTien = value; PropertyHasChanged("GiaTien"); }
        }

        private int? _UserCreated = Session.LoginID;
        public int? UserCreated
        {
            get { return this._UserCreated; }
            set { this._UserCreated = value; PropertyHasChanged("UserCreated"); }
        }

        private DateTime? _DateCreated = DateTime.MaxValue;
        public DateTime? DateCreated
        {
            get { return this._DateCreated; }
            set { this._DateCreated = value; PropertyHasChanged("DateCreated"); }
        }

        private int? _UserModify = null;
        public int? UserModify
        {
            get { return this._UserModify; }
            set { this._UserModify = value; PropertyHasChanged("UserModify"); }
        }

        private DateTime? _DateModify = null;
        public DateTime? DateModify
        {
            get { return this._DateModify; }
            set { this._DateModify = value; PropertyHasChanged("DateModify"); }
        }

        private bool? _Deleted = false;
        public bool? Deleted
        {
            get { return this._Deleted; }
            set { this._Deleted = value; PropertyHasChanged("Deleted"); }
        }

        private int? _STT0 = 0;
        public int? STT0
        {
            get { return _STT0; }
            set { _STT0 = value; }
        }

        protected override object GetIdValue()
        {
            return _KBDienNaoID.Value;
        }
        #endregion Business Properties
        //==========================================================================

        #region Factory Methods
        public void SetIsNew()
        {
            MarkNew();
        }

        public void SetIsOld()
        {
            MarkOld();
        }

        public void SetIsDirty()
        {
            MarkDirty();
        }

        public void SetIsChild()
        {
            MarkAsChild();
        }

        public object GetValue(string fieldName)
        {
            PropertyInfo propInfo = this.GetType().GetProperty(fieldName);
            return propInfo.GetValue(this, null);
        }

        public void SetValue(string fieldName, object value)
        {
            PropertyInfo propInfo = this.GetType().GetProperty(fieldName);
            propInfo.SetValue(this, value, null);
            MarkDirty();
        }

        private static int newKBDienNaoID = -1;
        private KBDienNaoBO()
        {
            _KBDienNaoID = newKBDienNaoID--;
        }

        public KBDienNaoBO(SqlDataReader dataReader)
        {
            MarkAsChild();
            Fetch(dataReader);
            MarkOld();
        }

        public KBDienNaoBO(SqlDataReader dataReader, bool isRoot)
        {
            if (!isRoot)
                MarkAsChild();
            Fetch(dataReader);
            MarkOld();
        }

        public static KBDienNaoBO NewRootKBDienNaoBO()
        {
            return DataPortal.Create<KBDienNaoBO>(new RootCriteria());
        }

        internal static KBDienNaoBO NewChildKBDienNaoBO()
        {
            return DataPortal.Create<KBDienNaoBO>(new ChildCriteria());
        }

        public static KBDienNaoBO GetRootKBDienNaoBO(int _KBDienNaoID)
        {
            return DataPortal.Fetch<KBDienNaoBO>(new RootCriteria(_KBDienNaoID));
        }

        public static KBDienNaoBO GetRootKBDienNaoBOByWhere(string where)
        {
            return DataPortal.Fetch<KBDienNaoBO>(where);
        }

        internal static KBDienNaoBO GetChildKBDienNaoBO(SqlDataReader dataReader)
        {
            return new KBDienNaoBO(dataReader);
        }

        public static void DeleteKBDienNaoBO(int _KBDienNaoID)
        {
            DataPortal.Delete(new RootCriteria(_KBDienNaoID));
        }

        public static void DeleteKBDienNaoBO(int _KBDienNaoID, bool directDelete)
        {
            DataPortal.Delete(new RootCriteria(_KBDienNaoID, directDelete));
        }
        #endregion Factory Methods
        //==========================================================================

        #region Criteria
        [Serializable()]
        public class RootCriteria
        {
            public int KBDienNaoID;
            public bool directDelete = false;
            public RootCriteria(int _KBDienNaoID)
            {
                this.KBDienNaoID = _KBDienNaoID;
                this.directDelete = false;
            }

            public RootCriteria(int _KBDienNaoID, bool directDelete)
            {
                this.KBDienNaoID = _KBDienNaoID;
                this.directDelete = directDelete;
            }

            public RootCriteria() { }
        }

        [Serializable()]
        public class ChildCriteria
        {
            public int KBDienNaoID;
            public bool directDelete = false;
            public ChildCriteria(int _KBDienNaoID)
            {
                this.KBDienNaoID = _KBDienNaoID;
                this.directDelete = false;
            }

            public ChildCriteria(int _KBDienNaoID, bool directDelete)
            {
                this.KBDienNaoID = _KBDienNaoID;
                this.directDelete = directDelete;
            }

            public ChildCriteria() { }
        }
        #endregion Criteria
        //==========================================================================

        #region Create
        [RunLocal]
        private void DataPortal_Create(RootCriteria criteria)
        {
        }

        private void DataPortal_Create(ChildCriteria criteria)
        {
            MarkAsChild();
            ValidationRules.CheckRules();
        }

        #endregion Create
        //==========================================================================

        #region Fetch
        [Transactional(TransactionalTypes.TransactionScope)]
        protected void DataPortal_Fetch(RootCriteria criteria)
        {
            this.Execute_Fetch(criteria);
        }

        protected void DataPortal_Fetch(string where)
        {
            this.Execute_Fetch(where);
        }

        protected void Execute_Fetch(RootCriteria criteria)
        {
            this.This_Fetch(criteria);
        }

        protected void Execute_Fetch(string where)
        {
            this.This_Fetch(where);
        }

        private void This_Fetch(RootCriteria criteria)
        {
            SqlDatabase db = new SqlDatabase(Session.DBConnectionString);
            SqlCommand cmd = (SqlCommand)db.GetStoredProcCommand("KBDienNaoBO_GetBO");
            db.AddInParameter(cmd, "@WhereExpression", SqlDbType.NVarChar, "[KBDienNaoID] = " + criteria.KBDienNaoID);
            using (SqlDataReader dataReader = (SqlDataReader)db.ExecuteReader(cmd))
            {
                if (dataReader.Read())
                    Fetch(dataReader);
            }
        }

        private void This_Fetch(string where)
        {
            SqlDatabase db = new SqlDatabase(Session.DBConnectionString);
            SqlCommand cmd = (SqlCommand)db.GetStoredProcCommand("KBDienNaoBO_GetBO");
            db.AddInParameter(cmd, "@WhereExpression", SqlDbType.NVarChar, where);
            using (SqlDataReader dataReader = (SqlDataReader)db.ExecuteReader(cmd))
            {
                if (dataReader.Read())
                    Fetch(dataReader);
            }
        }

        private void Fetch(SqlDataReader dataReader)
        {
            if (!(dataReader["KBDienNaoID"] is DBNull))
                this._KBDienNaoID = (int)dataReader["KBDienNaoID"];
            if (!(dataReader["Status"] is DBNull))
                this._Status = (int)dataReader["Status"];
            if (!(dataReader["KBDieuTriID"] is DBNull))
                this._KBDieuTriID = (int)dataReader["KBDieuTriID"];
            if (!(dataReader["KBYLenhID"] is DBNull))
                this._KBYLenhID = (int)dataReader["KBYLenhID"];
            if (!(dataReader["BenhNhanID"] is DBNull))
                this._BenhNhanID = (int)dataReader["BenhNhanID"];
            if (!(dataReader["NguoiChiDinhID"] is DBNull))
                this._NguoiChiDinhID = (int)dataReader["NguoiChiDinhID"];
            if (!(dataReader["NgayChiDinh"] is DBNull))
                this._NgayChiDinh = (DateTime)dataReader["NgayChiDinh"];
            if (!(dataReader["NguoiThucHienID"] is DBNull))
                this._NguoiThucHienID = (int)dataReader["NguoiThucHienID"];
            if (!(dataReader["NgayThucHien"] is DBNull))
                this._NgayThucHien = (DateTime)dataReader["NgayThucHien"];
            if (!(dataReader["KhoaThucHienID"] is DBNull))
                this._KhoaThucHienID = (int)dataReader["KhoaThucHienID"];
            if (!(dataReader["PhongThucHienID"] is DBNull))
                this._PhongThucHienID = (int)dataReader["PhongThucHienID"];
            if (!(dataReader["DMDienNaoID"] is DBNull))
                this._DMDienNaoID = (int)dataReader["DMDienNaoID"];
            if (!(dataReader["KyThuat"] is DBNull))
                this._KyThuat = (string)dataReader["KyThuat"];
            if (!(dataReader["TinhTrang"] is DBNull))
                this._TinhTrang = (string)dataReader["TinhTrang"];
            if (!(dataReader["SongAlpha"] is DBNull))
                this._SongAlpha = (string)dataReader["SongAlpha"];
            if (!(dataReader["TanSo"] is DBNull))
                this._TanSo = (string)dataReader["TanSo"];
            if (!(dataReader["BienDo"] is DBNull))
                this._BienDo = (string)dataReader["BienDo"];
            if (!(dataReader["ChiSo"] is DBNull))
                this._ChiSo = (string)dataReader["ChiSo"];
            if (!(dataReader["PhanUngVoiKichThich"] is DBNull))
                this._PhanUngVoiKichThich = (string)dataReader["PhanUngVoiKichThich"];
            if (!(dataReader["DoiXungHayKhong"] is DBNull))
                this._DoiXungHayKhong = (string)dataReader["DoiXungHayKhong"];
            if (!(dataReader["DongHoaNhip"] is DBNull))
                this._DongHoaNhip = (string)dataReader["DongHoaNhip"];
            if (!(dataReader["SongNhanh"] is DBNull))
                this._SongNhanh = (string)dataReader["SongNhanh"];
            if (!(dataReader["SongCham"] is DBNull))
                this._SongCham = (string)dataReader["SongCham"];
            if (!(dataReader["CacPhucBoSong"] is DBNull))
                this._CacPhucBoSong = (string)dataReader["CacPhucBoSong"];
            if (!(dataReader["Anh"] is DBNull))
                this._Anh = (byte[])dataReader["Anh"];
            if (!(dataReader["KetQua"] is DBNull))
                this._KetQua = (string)dataReader["KetQua"];
            if (!(dataReader["KetLuan"] is DBNull))
                this._KetLuan = (string)dataReader["KetLuan"];
            if (!(dataReader["GhiChu"] is DBNull))
                this._GhiChu = (string)dataReader["GhiChu"];
            if (!(dataReader["GiaTien"] is DBNull))
                this._GiaTien = (double)dataReader["GiaTien"];
            if (!(dataReader["UserCreated"] is DBNull))
                this._UserCreated = (int)dataReader["UserCreated"];
            if (!(dataReader["DateCreated"] is DBNull))
                this._DateCreated = (DateTime)dataReader["DateCreated"];
            if (!(dataReader["UserModify"] is DBNull))
                this._UserModify = (int)dataReader["UserModify"];
            if (!(dataReader["DateModify"] is DBNull))
                this._DateModify = (DateTime)dataReader["DateModify"];
            if (!(dataReader["Deleted"] is DBNull))
                this._Deleted = (bool)dataReader["Deleted"];

        }
        #endregion Fetch
        //==========================================================================

        #region Insert
        [Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_Insert()
        {
            this.Execute_Insert();
        }

        protected void Execute_Insert()
        {
            this.This_Insert();
        }

        private void This_Insert()
        {
            this._UserCreated = Session.LoginID;
            this._DateCreated = DateTime.MaxValue;
            this._UserModify = null;
            this._DateModify = null;
            this._Deleted = false;

            SqlDatabase db = new SqlDatabase(Session.DBConnectionString);
            SqlCommand cmd = (SqlCommand)db.GetStoredProcCommand("KBDienNaoBO_InsertBO");
            db.AddInParameter(cmd, "@Status", SqlDbType.Int, this._Status);
            db.AddInParameter(cmd, "@KBDieuTriID", SqlDbType.Int, this._KBDieuTriID);
            db.AddInParameter(cmd, "@KBYLenhID", SqlDbType.Int, this._KBYLenhID);
            db.AddInParameter(cmd, "@BenhNhanID", SqlDbType.Int, this._BenhNhanID);
            db.AddInParameter(cmd, "@NguoiChiDinhID", SqlDbType.Int, this._NguoiChiDinhID);
            db.AddInParameter(cmd, "@NgayChiDinh", SqlDbType.DateTime, this._NgayChiDinh);
            db.AddInParameter(cmd, "@NguoiThucHienID", SqlDbType.Int, this._NguoiThucHienID);
            db.AddInParameter(cmd, "@NgayThucHien", SqlDbType.DateTime, this._NgayThucHien);
            db.AddInParameter(cmd, "@KhoaThucHienID", SqlDbType.Int, this._KhoaThucHienID);
            db.AddInParameter(cmd, "@PhongThucHienID", SqlDbType.Int, this._PhongThucHienID);
            db.AddInParameter(cmd, "@DMDienNaoID", SqlDbType.Int, this._DMDienNaoID);
            db.AddInParameter(cmd, "@KyThuat", SqlDbType.NVarChar, this._KyThuat);
            db.AddInParameter(cmd, "@TinhTrang", SqlDbType.NVarChar, this._TinhTrang);
            db.AddInParameter(cmd, "@SongAlpha", SqlDbType.NVarChar, this._SongAlpha);
            db.AddInParameter(cmd, "@TanSo", SqlDbType.NVarChar, this._TanSo);
            db.AddInParameter(cmd, "@BienDo", SqlDbType.NVarChar, this._BienDo);
            db.AddInParameter(cmd, "@ChiSo", SqlDbType.NVarChar, this._ChiSo);
            db.AddInParameter(cmd, "@PhanUngVoiKichThich", SqlDbType.NVarChar, this._PhanUngVoiKichThich);
            db.AddInParameter(cmd, "@DoiXungHayKhong", SqlDbType.NVarChar, this._DoiXungHayKhong);
            db.AddInParameter(cmd, "@DongHoaNhip", SqlDbType.NVarChar, this._DongHoaNhip);
            db.AddInParameter(cmd, "@SongNhanh", SqlDbType.NVarChar, this._SongNhanh);
            db.AddInParameter(cmd, "@SongCham", SqlDbType.NVarChar, this._SongCham);
            db.AddInParameter(cmd, "@CacPhucBoSong", SqlDbType.NVarChar, this._CacPhucBoSong);
            db.AddInParameter(cmd, "@Anh", SqlDbType.Image, this._Anh);
            db.AddInParameter(cmd, "@KetQua", SqlDbType.NVarChar, this._KetQua);
            db.AddInParameter(cmd, "@KetLuan", SqlDbType.NVarChar, this._KetLuan);
            db.AddInParameter(cmd, "@GhiChu", SqlDbType.NVarChar, this._GhiChu);
            db.AddInParameter(cmd, "@GiaTien", SqlDbType.Float, this._GiaTien);
            db.AddInParameter(cmd, "@UserCreated", SqlDbType.Int, this._UserCreated);
            db.AddOutParameter(cmd, "@NewKBDienNaoID", SqlDbType.Int, 10);
            db.AddOutParameter(cmd, "@NewDateCreated", SqlDbType.DateTime, 4);
            db.ExecuteNonQuery(cmd);
            this._KBDienNaoID = (int)cmd.Parameters["@NewKBDienNaoID"].Value;
            this._DateCreated = (DateTime)cmd.Parameters["@NewDateCreated"].Value;
        }
        #endregion Insert
        //==========================================================================

        #region Update
        [Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_Update()
        {
            this.Execute_Update();
        }

        protected void Execute_Update()
        {
            this.This_Update();
        }

        private void This_Update()
        {
            this._UserModify = Session.LoginID;
            this._DateModify = DateTime.Now;

            SqlDatabase db = new SqlDatabase(Session.DBConnectionString);
            SqlCommand cmd = (SqlCommand)db.GetStoredProcCommand("KBDienNaoBO_UpdateBO");
            db.AddInParameter(cmd, "@KBDienNaoID", SqlDbType.Int, this._KBDienNaoID);
            db.AddInParameter(cmd, "@Status", SqlDbType.Int, this._Status);
            db.AddInParameter(cmd, "@KBDieuTriID", SqlDbType.Int, this._KBDieuTriID);
            db.AddInParameter(cmd, "@KBYLenhID", SqlDbType.Int, this._KBYLenhID);
            db.AddInParameter(cmd, "@BenhNhanID", SqlDbType.Int, this._BenhNhanID);
            db.AddInParameter(cmd, "@NguoiChiDinhID", SqlDbType.Int, this._NguoiChiDinhID);
            db.AddInParameter(cmd, "@NgayChiDinh", SqlDbType.DateTime, this._NgayChiDinh);
            db.AddInParameter(cmd, "@NguoiThucHienID", SqlDbType.Int, this._NguoiThucHienID);
            db.AddInParameter(cmd, "@NgayThucHien", SqlDbType.DateTime, this._NgayThucHien);
            db.AddInParameter(cmd, "@KhoaThucHienID", SqlDbType.Int, this._KhoaThucHienID);
            db.AddInParameter(cmd, "@PhongThucHienID", SqlDbType.Int, this._PhongThucHienID);
            db.AddInParameter(cmd, "@DMDienNaoID", SqlDbType.Int, this._DMDienNaoID);
            db.AddInParameter(cmd, "@KyThuat", SqlDbType.NVarChar, this._KyThuat);
            db.AddInParameter(cmd, "@TinhTrang", SqlDbType.NVarChar, this._TinhTrang);
            db.AddInParameter(cmd, "@SongAlpha", SqlDbType.NVarChar, this._SongAlpha);
            db.AddInParameter(cmd, "@TanSo", SqlDbType.NVarChar, this._TanSo);
            db.AddInParameter(cmd, "@BienDo", SqlDbType.NVarChar, this._BienDo);
            db.AddInParameter(cmd, "@ChiSo", SqlDbType.NVarChar, this._ChiSo);
            db.AddInParameter(cmd, "@PhanUngVoiKichThich", SqlDbType.NVarChar, this._PhanUngVoiKichThich);
            db.AddInParameter(cmd, "@DoiXungHayKhong", SqlDbType.NVarChar, this._DoiXungHayKhong);
            db.AddInParameter(cmd, "@DongHoaNhip", SqlDbType.NVarChar, this._DongHoaNhip);
            db.AddInParameter(cmd, "@SongNhanh", SqlDbType.NVarChar, this._SongNhanh);
            db.AddInParameter(cmd, "@SongCham", SqlDbType.NVarChar, this._SongCham);
            db.AddInParameter(cmd, "@CacPhucBoSong", SqlDbType.NVarChar, this._CacPhucBoSong);
            db.AddInParameter(cmd, "@Anh", SqlDbType.Image, this._Anh);
            db.AddInParameter(cmd, "@KetQua", SqlDbType.NVarChar, this._KetQua);
            db.AddInParameter(cmd, "@KetLuan", SqlDbType.NVarChar, this._KetLuan);
            db.AddInParameter(cmd, "@GhiChu", SqlDbType.NVarChar, this._GhiChu);
            db.AddInParameter(cmd, "@GiaTien", SqlDbType.Float, this._GiaTien);
            db.AddInParameter(cmd, "@UserModify", SqlDbType.Int, this._UserModify);
            db.AddInParameter(cmd, "@Deleted", SqlDbType.Bit, this._Deleted);

            db.AddOutParameter(cmd, "@NewDateModify", SqlDbType.DateTime, 4);
            db.ExecuteNonQuery(cmd);

            this._DateModify = (DateTime)cmd.Parameters["@NewDateModify"].Value;
        }
        #endregion Update
        //==========================================================================

        #region Delete
        [Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_DeleteSelf()
        {
            DataPortal_Delete(new RootCriteria(_KBDienNaoID.Value));
        }

        private void DataPortal_Delete(RootCriteria criteria)
        {
            this.Execute_Delete(criteria);
        }

        protected void Execute_Delete(RootCriteria criteria)
        {
            SqlDatabase db = new SqlDatabase(Session.DBConnectionString);
            SqlCommand cmd = (SqlCommand)db.GetStoredProcCommand("KBDienNaoBO_DeleteBO");
            db.AddInParameter(cmd, "@DirectDelete", SqlDbType.Bit, criteria.directDelete);
            db.AddInParameter(cmd, "@KBDienNaoID", SqlDbType.Int, criteria.KBDienNaoID);
            db.ExecuteNonQuery(cmd);
        }
        #endregion Delete
        //==========================================================================

        #region Internal method
        internal void Insert()
        {
            if (!this.IsDirty) return;
            DataPortal_Insert();
            MarkOld();
        }

        internal void Update()
        {
            if (!this.IsDirty) return;
            DataPortal_Update();
            MarkOld();
        }

        internal void DeleteSelf()
        {
            if (!this.IsDirty) return;
            if (this.IsNew) return;
            DataPortal_Delete(new RootCriteria(_KBDienNaoID.Value));
            MarkNew();
        }
        #endregion Internal method
        //==========================================================================
    }
}
